/*
 * GLPrivateBodyPack.h
 *
 *  Created on: Nov 14, 2014
 *      Author: yuliang
 */

#ifndef GLPRIVATEBODYPACK_H_
#define GLPRIVATEBODYPACK_H_

#include "LogicBase/GLContainerBase.h"

class CGLPrivateBodyPack : public CGLContainerBase {
	#define BODY_INVALID_STATUS_INDEX 201
	typedef std::map<Index_t, BodyStatusModel> MapIndexStatus_t;
public:
	CGLPrivateBodyPack(UserId_t uid);
	virtual ~CGLPrivateBodyPack();
	virtual bool DecodeContainerExtend(const std::string& info);
	virtual bool EncodeContainerExtend(std::string& info);

	inline void SetBodyStatus(BodyStatusModel model, Index_t index);
	inline void RmBodyStatus(BodyStatusModel model);
	inline bool ExistBodyStatus(Index_t index) const;
	inline Index_t GetStatusIndex(BodyStatusModel model) const;
	inline CGLGoodsBase* GetStatusBody(BodyStatusModel model);
protected:
	// 新建物品,并初始化
	virtual CGLGoodsBase* getGoods();
	virtual void setGoods(CGLGoodsBase* goods);
	virtual const GoodsFixInfo* getGoodsFixInfo(Type_t type) const;
private:
	MapIndexStatus_t m_IndexStatus;
	BodyIndexStatusInfo m_Status;
};

void CGLPrivateBodyPack::SetBodyStatus(BodyStatusModel model, Index_t index) {
	if (model >= BSModelCount) return;

	CGLGoodsBase* tBody = GetGoods(index);
	if (nullptr == tBody) return;

	Index_t tCurIndex = m_Status.m_StatusIndex[model];
	if (tCurIndex != BODY_INVALID_STATUS_INDEX)
		m_IndexStatus.erase(tCurIndex);

	MapIndexStatus_t::iterator it = m_IndexStatus.find(index);
	if (it != m_IndexStatus.end())
		m_Status.m_StatusIndex[model] = BODY_INVALID_STATUS_INDEX;;

	m_Status.m_StatusIndex[model] = index;
	m_IndexStatus[index] = model;
}

void CGLPrivateBodyPack::RmBodyStatus(BodyStatusModel model) {
	if (model >= BSModelCount) return;
	Index_t tCurIndex = m_Status.m_StatusIndex[model];
	if (tCurIndex != BODY_INVALID_STATUS_INDEX) {
		m_IndexStatus.erase(tCurIndex);
		m_Status.m_StatusIndex[model] = BODY_INVALID_STATUS_INDEX;
	}
}

bool CGLPrivateBodyPack::ExistBodyStatus(Index_t index) const {
	return m_IndexStatus.find(index) != m_IndexStatus.end();
}

Index_t CGLPrivateBodyPack::GetStatusIndex(BodyStatusModel model) const {
	return m_Status.m_StatusIndex[model];
}

CGLGoodsBase* CGLPrivateBodyPack::GetStatusBody(BodyStatusModel model) {
	Index_t tCurIndex = m_Status.m_StatusIndex[model];
	if (BODY_INVALID_STATUS_INDEX == tCurIndex)
		return nullptr;
	return GetGoods(tCurIndex);
}

#endif /* GLPRIVATEBODYPACK_H_ */
